<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/29
 * Time: 22:10
 */

include_once 'redis.php';

$page = $_GET['page'] ?? 1;//获取请求

$count = $redis->zCard("{$userInfo['uid']}:follow");// 获取我关注的用户总数

extract(page($count, $page));// 返回分页数组

$followIdList = $redis->zRange("{$userInfo['uid']}:follow", $start, $end);// 获取我关注的用户id列表

if (empty($followIdList)) {
    $list = [];// 关注列表数组
    $page = 0;// 页数为0
} else {
    foreach ($followIdList as $id) {
        $list[] = $redis->hGetAll("user:{$id}");
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的关注</title>
</head>
<body>
<table border="1">
    <tr>
        <td colspan="5" align="center">我的关注</td>
    </tr>
    <tr>
        <td colspan="2">
            <button onclick="jump_url('main.php');" style="width: 100%">返回主页面</button>
        </td>
        <td colspan="2">
            <button onclick="jump_url('followMe.php');" style="width: 100%">谁关注我</button>
        </td>
        <td>
            <button style="float: right;width: 100%" onclick="jump_url('logout.php');">退出登录</button>
        </td>
    </tr>
    <tr>
        <th>uid</th>
        <th>姓名</th>
        <th>电话</th>
        <th>年龄</th>
        <th>操作</th>
    </tr>
    <?php foreach ($list as $item) { ?>
        <tr>
            <td><?php echo $item['uid'] ?></td>
            <td><?php echo $item['name'] ?></td>
            <td><?php echo $item['phone'] ?></td>
            <td><?php echo $item['age'] ?></td>
            <td>
                <button onclick="jump_url('follow.php?uid=<?php echo $item['uid'] ?>&page=<?php echo $page ?>&type=cancel');"
                        style="width: 100%">取消关注
                </button>
            </td>
        </tr>
    <?php } ?>
    <tr>
        <td>
            <button onclick="jump_url('myFollow.php?page=1');" <?php echo $page <= 1 ? 'disabled' : '' ?>>首页</button>
        </td>
        <td>
            <button onclick="jump_url('myFollow.php?page=<?php echo $page <= 1 ? 1 : $page - 1 ?>');" <?php echo $page <= 1 ? 'disabled' : '' ?>>
                上一页
            </button>
        </td>
        <td>
            <button onclick="jump_url('myFollow.php?page=<?php echo $page >= $totalPage ? $totalPage : $page + 1 ?>');" <?php echo $page >= $totalPage ? 'disabled' : '' ?>>
                下一页
            </button>
        </td>
        <td>
            <button onclick="jump_url('myFollow.php?page=<?php echo $totalPage ?>');" <?php echo $page >= $totalPage ? 'disabled' : '' ?>>
                末页
            </button>
        </td>
        <td>当前页：<?php echo $page ?> / 总页数：<?php echo $totalPage ?></td>
    </tr>
</table>
</body>
</html>